<template>
  <div style="height: 6vh;background-color:#fff;padding:10px 20px;">
    <span style="line-height:60px;font-size:20px;">余额查询</span>
  </div>
  <!-- 账户搜索 -->
  <el-card style="margin:20px;height: 70px;">
    <el-form :inline="true" @keydown.enter="loadAccount">
      <el-form-item label="姓名">
        <el-input placeholder="请输入内容" style="width:220px;" v-model="selectAccountForm.username" ></el-input>
      </el-form-item>
      <el-form-item label="卡号">
        <el-input placeholder="请输入内容" style="width:220px;" v-model="selectAccountForm.card"></el-input>
      </el-form-item>
      <el-form-item label="开户组织" style="width:290px;">
        <el-input placeholder="请输入内容" style="width:220px;" v-model="selectAccountForm.organization"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="loadAccount">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 账户列表 -->
  <el-card style="margin:20px;">
    <el-table :data="AccountArr">
      <el-table-column type="index" label="编号" width="80" align="center"/>
      <el-table-column prop="username" label="老人姓名" align="center"/>
      <el-table-column prop="card" label="卡号" align="center"/>
      <el-table-column prop="spare" label="备用金" align="center"/>
      <el-table-column prop="fixedBalance" label="固定余额" align="center"/>
      <el-table-column prop="expendBalance" label="消费余额" align="center"/>
      <el-table-column prop="createTime" label="创建时间" align="center"/>
      <el-table-column prop="organization" label="开户组织" align="center"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="editVehicle(scope.row.id)"><el-icon style="font-size: 25px;margin-left: 35px;"><Coin /></el-icon></el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import qs from "qs";
import {ElMessage} from "element-plus";

//搜索账户信息查询条件
const selectAccountForm = ref({
  username:'',
  card:'',
  organization:''
})
//定义重置搜索的方法
const resetSearch = ()=>{
  selectAccountForm.value = {};
  loadAccount()
}
//定义数组用来保存账户列表数据
const AccountArr = ref([]);
//定义加载账户的方法
const loadAccount = ()=>{
  let data = qs.stringify(selectAccountForm.value);
  console.log(data);
  axios.get(BASE_URL+'/v1/account/select?'+data).then((response)=>{
    if(response.data.code == 2000){
      AccountArr.value = response.data.data;
    }else{
      ElMessage.error(response.data.msg);
    }
  })
}
onMounted(()=>{
  loadAccount();
})
</script>

<style scoped>

</style>